package com.bytedance.improvingroad.adapter

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bytedance.improvingroad.R
import com.bytedance.improvingroad.model.SlideCardBean
import com.bytedance.improvingroad.utils.Utils

/**
 * Created by chenxiong
 * date 11/17/21
 */
class SlideCardAdapter(private val datas:MutableList<SlideCardBean>): RecyclerView.Adapter<SlideCardAdapter.SlideViewHolder>() {

    class SlideViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val ivImage: ImageView = itemView.findViewById(R.id.iv)
        val tvName: TextView = itemView.findViewById(R.id.tvName)
        val posTitle: TextView = itemView.findViewById(R.id.tvPrecent)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SlideViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_swipe_card, parent, false)
        return SlideViewHolder(view)
    }

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(holder: SlideViewHolder, position: Int) {
        val data = datas[position]
        Glide.with(holder.itemView.context).load(data.url).into(holder.ivImage)
        holder.tvName.text = data.name
        holder.posTitle.text = "${data.position}/${datas.size}"
    }

    override fun getItemCount() = datas.size
}